<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>本地控制面板</title>
    <style>
        /* 新增图片样式 */
        .image-with-border {
            display: block;
            /* 确保��片独占一行 */
            margin: 5% auto;
            /* 居中图片 */
            border: 5px solid #93929e;
            /* 添加边框，颜色���按钮一致 */
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
            /* 可选��加阴影效果 */
            max-width: 100%;
            /* 确保图片不会超出容器宽度 */
            width: 80%;
            /* 自动调整��� */
            height: auto;
            /* 自动调整高度 */
        }

        /* 按钮容器 */
        .button-container {
            display: flex;
            justify-content: center;
            align-items: center;
            position: relative;
            /* 添加相对定位 */
            margin-top: 5px;
            /* 在图片下方添加一��间距 */
            gap: 100px;
        }

        /* 按钮样式 */
        .svg-button {
            width: 80px;
            height: 80px;
            cursor: pointer;
            margin: 5px;
        }

        /* 提示样式 */
        .message {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            font-size: 16px;
            color: #93929e;
            font-weight: bolder;
        }
    </style>
</head>

<body>
    <img src="/video_feed" class="image-with-border" width="50%" alt="see">
    <div class="all-buttons">
        <div class="button-container">
            <!-- 前���按钮 -->
            <svg class="svg-button" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
                onclick="showMessage('前进');">
                <path fill="#41b883"
                    d="M12 2q-.327 0-.642.005l-.616.017l-.299.013l-.579.034l-.553.046c-4.785.464-6.732 2.411-7.196 7.196l-.046.553l-.034.579q-.008.147-.013.299l-.017.616l-.004.318L2 12q0 .327.005.642l.017.616l.013.299l.034.579l.046.553c.464 4.785 2.411 6.732 7.196 7.196l.553.046l.579.034q.147.008.299.013l.616.017L12 22l.642-.005l.616-.017l.299-.013l.579-.034l.553-.046c4.785-.464 6.732-2.411 7.196-7.196l.046-.553l.034-.579q.008-.147.013-.299l.017-.616L22 12l-.005-.642l-.017-.616l-.013-.299l-.034-.579l-.046-.553c-.464-4.785-2.411-6.732-7.196-7.196l-.553-.046l-.579-.034l-.299-.013l-.616-.017l-.318-.004zm-.148 5.011l.058-.007L12 7l.075.003l.126.017l.111.03l.111.044l.098.052l.104.074l.082.073l4 4a1 1 0 0 1-1.32 1.497l-.094-.083L13 10.415V16a1 1 0 0 1-1.993.117L11 16v-5.585l-2.293 2.292a1 1 0 0 1-1.32.083l-.094-.083a1 1 0 0 1-.083-1.32l.083-.094l4-4a1 1 0 0 1 .112-.097l.11-.071l.114-.054l.105-.035z" />
            </svg>
        </div>
        <div class="button-container">
            <!-- 左移按钮 -->
            <svg class="svg-button" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
                onclick="showMessage('左移');">
                <path fill="#41b883"
                    d="m12 2l.324.001l.318.004l.616.017l.299.013l.579.034l.553.046c4.785.464 6.732 2.411 7.196 7.196l.046.553l.034.579q.008.147.013.299l.017.616L22 12l-.005.642l-.017.616l-.013.299l-.034.579l-.046.553c-.464 4.785-2.411 6.732-7.196 7.196l-.553.046l-.579.034q-.147.008-.299.013l-.616.017L12 22l-.642-.005l-.616-.017l-.299-.013l-.579-.034l-.553-.046c-4.785-.464-6.732-2.411-7.196-7.196l-.046-.553l-.034-.579l-.013-.299l-.017-.616Q2 12.327 2 12l.001-.324l.004-.318l.017-.616l.013-.299l.034-.579l.046-.553c.464-4.785 2.411-6.732 7.196-7.196l.553-.046l.579-.034q.147-.008.299-.013l.616-.017Q11.673 2 12 2m.707 5.293a1 1 0 0 0-1.414 0l-4 4a1 1 0 0 0-.2.284l-.022.052a1 1 0 0 0-.06.222l-.008.067l-.002.063v-.035v.073a1 1 0 0 0 .07.352l.023.052l.03.061l.022.037l.05.074l.024.03l.073.082l4 4l.094.083a1 1 0 0 0 1.32-.083l.083-.094a1 1 0 0 0-.083-1.32L10.415 13H16l.117-.007A1 1 0 0 0 16 11h-5.585l2.292-2.293l.083-.094a1 1 0 0 0-.083-1.32" />
            </svg>

            <!-- 按钮提示 -->
            <div class="message" id="message"></div>

            <!-- 右移按钮 -->
            <svg class="svg-button" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
                onclick="showMessage('右移');">
                <path fill="#41b883"
                    d="M12 2q-.327 0-.642.005l-.616.017l-.299.013l-.579.034l-.553.046c-4.785.464-6.732 2.411-7.196 7.196l-.046.553l-.034.579q-.008.147-.013.299l-.017.616l-.004.318L2 12q0 .327.005.642l.017.616l.013.299l.034.579l.046.553c.464 4.785 2.411 6.732 7.196 7.196l.553.046l.579.034q.147.008.299.013l.616.017L12 22l.642-.005l.616-.017l.299-.013l.579-.034l.553-.046c4.785-.464 6.732-2.411 7.196-7.196l.046-.553l.034-.579q.008-.147.013-.299l.017-.616L22 12l-.005-.642l-.017-.616l-.013-.299l-.034-.579l-.046-.553c-.464-4.785-2.411-6.732-7.196-7.196l-.553-.046l-.579-.034l-.299-.013l-.616-.017l-.318-.004zm.613 5.21l.094.083l4 4a1 1 0 0 1 .097.112l.071.11l.054.114l.035.105l.03.148L17 12l-.003.075l-.017.126l-.03.111l-.044.111l-.052.098l-.074.104l-.073.082l-4 4a1 1 0 0 1-1.497-1.32l.083-.094L13.585 13H8a1 1 0 0 1-.117-1.993L8 11h5.585l-2.292-2.293a1 1 0 0 1-.083-1.32l.083-.094a1 1 0 0 1 1.32-.083" />
            </svg>
        </div>
        <div class="button-container">
            <!-- 后退按钮 -->
            <svg class="svg-button" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
                onclick="showMessage('后退');">
                <path fill="#41b883"
                    d="M12 2q-.327 0-.642.005l-.616.017l-.299.013l-.579.034l-.553.046c-4.785.464-6.732 2.411-7.196 7.196l-.046.553l-.034.579q-.008.147-.013.299l-.017.616l-.004.318L2 12q0 .327.005.642l.017.616l.013.299l.034.579l.046.553c.464 4.785 2.411 6.732 7.196 7.196l.553.046l.579.034q.147.008.299.013l.616.017L12 22l.642-.005l.616-.017l.299-.013l.579-.034l.553-.046c4.785-.464 6.732-2.411 7.196-7.196l.046-.553l.034-.579q.008-.147.013-.299l.017-.616L22 12l-.005-.642l-.017-.616l-.013-.299l-.034-.579l-.046-.553c-.464-4.785-2.411-6.732-7.196-7.196l-.553-.046l-.579-.034l-.299-.013l-.616-.017l-.318-.004zm0 5a1 1 0 0 1 .993.883L13 8v5.585l2.293-2.292a1 1 0 0 1 1.32-.083l.094.083a1 1 0 0 1 .083 1.32l-.083.094l-4 4a1 1 0 0 1-.112.097l-.11.071l-.114.054l-.105.035l-.149.03L12 17l-.075-.003l-.126-.017l-.111-.03l-.111-.044l-.098-.052l-.092-.064l-.094-.083l-4-4a1 1 0 0 1 1.32-1.497l.094.083L11 13.585V8a1 1 0 0 1 1-1" />
            </svg>
        </div>
    </div>

    <script>
        const buttonStates = {
            forward: false,
            lift: false,
            right: false,
            backward: false
        };
        function showMessage(direction) {
            const messageElement = document.getElementById('message');

            // ��换按钮状态
            buttonStates[direction] = !buttonStates[direction];

            // 根据当前状态显示信���
            if (buttonStates[direction]) {
                messageElement.textContent = `${direction} - 启动`;
                switch(direction) {
                    case '前进' :
                        sendRequest('Q', 'B');
                        break;
                    case '后退' :
                        sendRequest('H', 'B');
                        break;
                    case '左移' :
                        sendRequest('Z', 'B');
                        break;
                    case '右移' :
                        sendRequest('Y', 'B');
                        break;
                }
            } else {
                messageElement.textContent = `${direction} - 停止`;
                switch(direction) {
                    case '���进' :
                        sendRequest('Q', 'S');
                        break;
                    case '后退' :
                        sendRequest('H', 'S');
                        break;
                    case '左移' :
                        sendRequest('Z', 'S');
                        break;
                    case '��移' :
                        sendRequest('Y', 'S');
                        break;
                }
            }
        }

        function sendRequest(direction, action) {
            // 根据按钮状态重���请求 URL
            const url = `/${direction}${action}`;

            // 发送GET请��到后端API
            fetch(url, {
                method: 'GET',
            })
            .catch(error => {
                // 处理错误
                console.error('Error fetching data:', error);
            });
        }

        // 为按钮点击事件添加处���函数
        function handleClick(direction, requestType) {
            showMessage(direction);
        }
    </script>
</body>

</html>